package com.lyy.document.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyy.common.utils.UUIDUtils;
import com.lyy.document.dao.DocDocumentHistoryDao;
import com.lyy.document.pojo.DocDocumentHistory;
import com.lyy.document.service.DocDocumentHistoryService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 文件历史记录(DocDocumentHistory)表服务实现类
 *
 * @author Yw
 * @since 2021-02-01 17:23:46
 */
@Service
public class DocDocumentHistoryServiceImpl extends ServiceImpl<DocDocumentHistoryDao, DocDocumentHistory> implements DocDocumentHistoryService {


    /**
     * 添加文件历史记录
     *
     * @param docDocumentHistory
     */
    @Override
    public void createDocDocumentHistory(DocDocumentHistory docDocumentHistory) {
        docDocumentHistory.setCreateDate(new Date());
        baseMapper.insert(docDocumentHistory);
    }

    /**
     * 根据主键修改文件历史记录
     *
     * @param docDocumentHistory
     */
    @Override
    public void updateDocDocumentHistory(DocDocumentHistory docDocumentHistory) {
        baseMapper.update(docDocumentHistory, new UpdateWrapper<DocDocumentHistory>()
                .eq("id", docDocumentHistory.getId())
        );
    }

    /**
     * 根据主键删除文件历史记录
     *
     * @param id 文档操作记录id
     * @return
     */
    @Override
    public void deleteDocDocumentHistory(DocDocumentHistory docDocumentHistory) {
        baseMapper.delete(new UpdateWrapper<DocDocumentHistory>()
                .eq("id", docDocumentHistory.getId())
        );
    }

    /**
     * 根据主键查询文件历史记录详情
     *
     * @param id 文档操作记录id
     * @return
     */
    @Override
    public DocDocumentHistory getDocDocumentHistory(DocDocumentHistory docDocumentHistory) {
        return baseMapper.selectOne(new QueryWrapper<DocDocumentHistory>()
                .eq("id", docDocumentHistory.getId())
        );
    }

    /**
     * 批量添加文件历史记录
     *
     * @param docDocumentHistorys
     */
    @Override
    public int batchInsert(List<DocDocumentHistory> docDocumentHistorys) {
        return baseMapper.batchInsert(docDocumentHistorys);
    }


    /**
     * 批量修改文件历史记录
     *
     * @param docDocumentHistorys
     */
    @Override
    public int batchUpdate(List<DocDocumentHistory> docDocumentHistorys) {
        return baseMapper.batchUpdate(docDocumentHistorys);
    }

    /**
     * 查询文件历史记录列表
     *
     * @param docDocumentHistory
     */
    @Override
    public List<DocDocumentHistory> selectDocDocumentHistoryList(DocDocumentHistory docDocumentHistory) {
        return baseMapper.selectDocDocumentHistoryList(docDocumentHistory);
    }

    /**
     * 查询文件历史记录数量
     *
     * @param docDocumentHistory
     */
    @Override
    public int selectDocDocumentHistoryCount(DocDocumentHistory docDocumentHistory) {
        return baseMapper.selectDocDocumentHistoryCount(docDocumentHistory);
    }


    /**
     * 导入文件历史记录excel
     *
     * @param docDocumentHistorys
     */
    @Override
    public List<Map<String, String>> importDocDocumentHistoryExcel(List<DocDocumentHistory> docDocumentHistorys) {
        List<Map<String, String>> mapList = new ArrayList<>();
        docDocumentHistorys.forEach(docDocumentHistory -> {
            docDocumentHistory.setId(UUIDUtils.getUUIDTWO());
            Map<String, String> map = new HashMap<>();
            map.put("status", "0");
            map.put("reason", "导入成功");
            mapList.add(map);
        });
        batchInsert(docDocumentHistorys);
        return mapList;
    }
}